// import { wxShare } from '@adjacentech/adj-we-lib';
import * as wxShare from './wxLib';

const requestUrl = "https://scrm.adjacentech.com/scrm/upm";
const APP_ID = "wx23427f1d33d75687";

const share = (
  config: { imgUrl?: string; title?: string; link?: string; content?: string } = {},
) => {
  // 初始化未完成，将当前方法安排进队列
  if (!isInit) {
    initFinishExcute.push(share.bind({}, config));
    return;
  }
  wxShare.share();
};

let isInit = false;
let initFinishExcute: Function[] = [];

// 初始化
const init = async () => {
  wxShare.init({
    wxOpenUrl: `https://wx-component.adjacentech.com/merchant/jsapi-sign`,
    env: 'production',
    userId: window.sessionStorage.getItem('openId'),
    wxShareUrl: `${requestUrl}/wx/share`,
  });

  await wxShare.configAndHideMenu({ appId: APP_ID });
  isInit = true;
  if (initFinishExcute.length > 0) {
    // 有需要执行的队列
    initFinishExcute.forEach(item => item());
  }
};

export default {
  share,
  init,
};
